import 'package:enjoy_plus_three2/pages/house/building_list.dart';
import 'package:enjoy_plus_three2/pages/house/house_form.dart';
import 'package:enjoy_plus_three2/pages/house/house_list.dart';
import 'package:enjoy_plus_three2/pages/house/location_list.dart';
import 'package:enjoy_plus_three2/pages/house/room_list.dart';
import 'package:enjoy_plus_three2/pages/notFound/index.dart';
import 'package:enjoy_plus_three2/pages/notice/index.dart';
import 'package:enjoy_plus_three2/pages/profile/index.dart';
import 'package:enjoy_plus_three2/utils/token.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import '../pages/login/index.dart';
import '../pages/tab_bar_page.dart';

class RouterManager{
static Map<String, WidgetBuilder> routes={
'/': (context) => const TabBarPage(),
      '/detail': (context) => const NoticeDetail(),
      '/login': (context) => const LoginPage(),
};
//思路分析
    //登录拦截：无需拦截：首页+公告详情+登录页ss
    //其他页面无需
    //1.判断访问的页面是否为登录页
    //不是登录页的话，且token不存在，进行拦截到登录页
    //2.如果访问的是个人页面，token存在则正常
    //3.非以上情况，直接放回null

 static Route<dynamic> generateRoute(RouteSettings settings) {
      final tokenManager = TokenManager();
      final token = tokenManager.getToken() ?? '';
      if (token.isEmpty && settings.name != '/login') {
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }

      if (settings.name == '/profile') {
        return MaterialPageRoute(
            builder: (context) =>
                ProfilePage(userInfo: settings.arguments as Map));
      }
      if (settings.name == '/house_list') {
        return MaterialPageRoute(builder: (context) => const HouseList());
      }
      if (settings.name == '/location_list') {
        return MaterialPageRoute(builder: (context) => const LocationList());
      }
     if (settings.name == '/building_list') {
        return MaterialPageRoute(
            builder: (context) =>
                BuildingList(point: (settings.arguments as Map)['point']));
      }
      if (settings.name == '/room_list') {
        Map temp = settings.arguments as Map;
        return MaterialPageRoute(builder: (context) =>  RoomList(
          point: temp['point'],
          building: temp['building'],
        ));
      }
      //跳转至房屋详情    
      if (settings.name == '/house_form') {
  return MaterialPageRoute(
      builder: (context) => HouseForm(
          params: settings.arguments as Map,
      )
  );
}

      return MaterialPageRoute(builder: (context) => const NotFound());
    }


}